package leetcode.code0464;

public class Solution extends Solution464 {

//	private List<Integer> temp = new ArrayList<>();
//	private List<List<Integer>> ans = new ArrayList<>();

	@Override
	public boolean canIWin(int maxChoosableInteger, int desiredTotal) {
		boolean[] pool = new boolean[21];
		boolean b = this.canIWin(pool, maxChoosableInteger, desiredTotal);
//		H.printObject(ans);
		return b;
	}

	public boolean canIWin(boolean[] pool, int maxChoosableInteger, int desiredTotal) {
		for (int i = 1; i <= maxChoosableInteger; i++) {
			if (!pool[i]) {
				if (i >= desiredTotal) {
					return true;
				}
				pool[i] = true;
				boolean b = canIWin(pool, maxChoosableInteger, desiredTotal - i);
				pool[i] = false;// 这句话在25不行?
				if (!b) {
//					ans.add(new ArrayList<>(temp));
					return true;
				}
			}
		}
		return false;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
//		for (int i = 11; i <= 41; i++) {
//			boolean b = so.canIWin(10, i);
//			System.out.println(i + " -> " + b);
//		}
		boolean b = so.canIWin(10, 21);
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();
	}

}
